package com.wy.framework.actions.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.wy.framework.constants.RtnCodeConstant;
import com.wy.framework.exceptions.ServiceException;
import com.wy.framework.actions.AbstractBaseAction;

/**
 * 项目名称：openportal
 * 类名称：JsonErrorAction
 * 类描述：json包的控制器异常时回调处理
 * 创建人：张旭星
 * 创建时间：2015-12-28 下午7:37:07
 * 修改人：张旭星
 * 修改时间：2015-12-28 下午7:37:07
 * 版本信息：@version 1.0
 * Copyright (c) 2015万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version 
 */
public class JsonErrorAction extends AbstractBaseAction {
	private static Logger logger = LoggerFactory
			.getLogger(JsonErrorAction.class);

	@Override
	public String execute() {
		Object exception = ActionContext.getContext().getValueStack()
				.findValue("exception");
		if (exception != null && exception instanceof Exception) {
			if (exception instanceof ServiceException) {
				rspCode = ((ServiceException) exception).getRspCode();
			} else {
				rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
			}
		} else {
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		MDC.put("CODE", rspCode);
		logger.error("JSON请求系统处理异常:{},{}", rspCode, rspMsg);
		logger.error("详细异常信息", exception);
		MDC.remove("CODE");
		return Action.SUCCESS;
	}
}
